#!/bin/bash
# Rust WASM Filter 编译脚本

echo "开始编译Rust WASM Filter插件..."

# 检查是否安装了wasm32-unknown-unknown目标
if ! rustup target list | grep -q "wasm32-unknown-unknown (installed)"; then
    echo "安装wasm32-unknown-unknown目标..."
    rustup target add wasm32-unknown-unknown
fi

# 编译为WebAssembly
echo "编译为WASM模块..."
cargo build --target wasm32-unknown-unknown --release

# 检查编译结果
if [ -f "target/wasm32-unknown-unknown/release/simple_filter.wasm" ]; then
    echo "✅ 编译成功！"
    echo "WASM文件位置: $(pwd)/target/wasm32-unknown-unknown/release/simple_filter.wasm"
    
    # 显示文件大小
    ls -lh target/wasm32-unknown-unknown/release/simple_filter.wasm
else
    echo "❌ 编译失败！"
    exit 1
fi

echo "编译完成。"